import bpy
from bpy.props import BoolProperty, FloatProperty
from bpy.types import UIList

from ..ops import queue


class AssetRender(UIList):
    bl_idname = 'UI_UL_DRAW_RENDER_MASTER_ASSET_RENDER'
    from ..utils.render_item import RenderItem

    split_factor: FloatProperty(name='左右拆分系数',
                                max=0.99,
                                default=0.7,
                                min=0.01,
                                )

    show_file_path: BoolProperty(name='显示文件路径', default=True)
    show_file_size: BoolProperty(name='显示文件大小', default=False)

    def draw_item(self, context: 'bpy.types.Object', layout: 'bpy.types.UILayout', data: 'AnyType', item: RenderItem,
                  icon: int, active_data: 'AnyType', active_property: str, index: int = 0, flt_flag: int = 0):
        row = layout.row(align=True)
        item.draw(row, self)

    def draw_filter(self, context: 'bpy.types.Context', layout: 'bpy.types.UILayout'):
        pref = queue.QueueUtils.pref_()
        column = layout.column()
        row = column.row(align=True)
        sub_row = row.row(align=True)
        sub_row.prop(self, 'filter_name')
        sub_row.prop(self, 'use_filter_invert',
                     icon='ARROW_LEFTRIGHT',
                     toggle=True,
                     icon_only=True,
                     )
        if not (self.use_filter_sort_lock and self.bitflag_filter_item):
            sub_row = sub_row.row(align=True)
            sub_row.prop(self, 'use_filter_sort_alpha',
                         toggle=True,
                         icon_only=True,
                         )

            icon = 'SORT_DESC' if (
                    self.bitflag_filter_item and self.use_filter_sort_reverse) else 'SORT_ASC'

            sub_row.prop(self, 'use_filter_sort_reverse',
                         icon=icon,
                         toggle=True,
                         icon_only=True,
                         )
        column.prop(self, 'split_factor')
        column.prop(pref, 'split_queue_list')

        row = column.row(align=True)
        row.prop(self, 'show_file_path')
        row.prop(self, 'show_file_size')
        row.prop(pref, 'show_detailed_render_info')


class_tuple = (
    AssetRender,
)

reg_class, un_reg_class = bpy.utils.register_classes_factory(class_tuple)


def register():
    reg_class()


def unregister():
    un_reg_class()
